package wikitools.util;

import wikitools.model.RSSDate;

import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.converters.Converter;
import com.thoughtworks.xstream.converters.MarshallingContext;
import com.thoughtworks.xstream.converters.UnmarshallingContext;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.xml.DomDriver;
import com.thoughtworks.xstream.tools.benchmark.targets.Person;

public class RSSDateConverter implements Converter {

    public boolean canConvert(Class clazz) {
        return clazz.equals(RSSDate.class);
    }
    
    

    public  void marshal(Object value,
            HierarchicalStreamWriter writer, MarshallingContext context) {
        RSSDate date = (RSSDate) value;
        writer.setValue(date.toString());
    }

    public Object unmarshal(HierarchicalStreamReader reader,
            UnmarshallingContext context) {
        RSSDate date = new RSSDate();
        return date;
    }

    public static void main(String[] args) {
        XStream xStream = new XStream(new DomDriver());
        xStream.registerConverter(new RSSDateConverter());
        xStream.alias("pubDate", RSSDate.class);
        System.out.println(xStream.toXML(new RSSDate()));

    }
}
